#include "processbar.h"
const char* label ="|/-\\";
const char* label2 ="|/-\\";
void process()
{
    char buffer[NUM]={0};
    int cnt=0;
    buffer[0]=Head;
    while(cnt<=100)
    {
        printf("[%-100s][%3d%%][%c]\r",buffer,cnt,label[cnt%4]);
        fflush(stdout);
        buffer[cnt++]=Body;
        if(cnt<100) buffer[cnt]=Head;
        usleep(50000);
    }
    printf("\n");
}

char buffer[NUM]={0};
void process_flush(double rate)
{
    static cnt=0;
    if(rate<1.0) buffer[0]=Head;
    printf("[%-100s][%.2f%%][%c]\r",buffer,rate,label2[cnt%4]);
    fflush(stdout);
    buffer[(int)rate]=Body;
    if((int)rate+1<100) buffer[(int)(rate+1)]=Head;
    if(rate>=100.0) printf("\n");
    cnt++;
}

